{extend name="base" /}
{block name="css"}
{css href="__CSS__/invite.css" /}
{/block}
{block name="body"}
<!-- 主要内容 开始 -->
<div class="weui-tab__bd-item">
    <header class="weui-navBar weui-navBar-fixed">
        <a href="javascript:history.go(-1);" class="weui-navBar-item">
            <i class="icon iconfont icon-fanhui f-white"></i>
        </a>
        <div class="weui-center">
            <span class="weui-center-title f-white">邀请好友</span>
        </div>
        <a href="javascript:;" class="weui-navBar-item">
        </a>
    </header>
    <div class="weui-tab__panel">
        <div class="divHeight"></div>
        <div class="invite">
            <div class="slogan">
                <img src="__IMG__/logo.png">
            </div>
            <div class="copy-code">
                <p>我的邀请码  <span class="weui-btn_copy">复制</span></p>
                <div class="divHeight"></div>
                <span id="not-input">{$info.share_code|default=''}</span>
            </div>

            <div class="divhigh"></div>
            <div class="qrcode"></div>
            <div class="divHeight"></div>
            <p class="demo-tips">扫描上方二维码直接注册</p>
        </div>
    </div>
</div>
<!-- 主要内容 结束 -->
{/block}
{block name="js"}
{js href="__JS__/jquery.qrcode.min.js" /}
<script type="text/javascript">
  $(function () {
    $('.qrcode').qrcode({
        render: "canvas",
        width: 200,
        height: 200,
        correctLevel: 0,
        text: '{$Request.domain}/register/code/{$info.share_code}.html'
    });

    $('.weui-btn_copy').click(function() {
        var createInput =document.createElement('input');
        // 防止键盘被调起
        createInput.setAttribute('readonly','readonly');
        createInput.setAttribute('value',document.getElementById('not-input').innerText);
        document.body.appendChild(createInput);

        createInput.select(); //ios 不支持 但chrome 支持
        createInput.setSelectionRange(0, createInput.value.length); // chrome 不支持 但ios支持
        // alert(createInput.value.length)
        if (document.execCommand('copy')) {
            document.execCommand('copy');
            $.toast("复制成功", 'text');
        }else {
            $.toast("你的浏览器不支持复制功能，请升级或更换你的浏览器", 'text');
        }
        document.body.removeChild(createInput);
    });
  });
</script>
{/block}